package com.zcy.model;
import com.zcy.view.Start;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Brand extends Component{
    //卡牌名称
    private String name;

    //卡牌状态  true-灰色
    private boolean isGray;

    //正常图片
    private Image image;

    //置灰图片
    private Image grayImage;

    //设置坐标
    private Integer x;
    private Integer y;

    //设置高度 宽度
    private Integer width;
    private Integer height;
    //声明格子对象
    private Cell cell;
    public Cell getCell(){
        return cell;
    }
    public void setCell(Cell cell){
        this.cell = cell;
    }

    //定义构造方法
    public Brand(String name){
        //卡牌名称赋值
        this.name = name;
        //设置默认图片
        this.image = Toolkit.getDefaultToolkit().getImage("imgs/"+ name +".png");
        //设置灰色图片
        this.grayImage = Toolkit.getDefaultToolkit().getImage("imgs/"+ name +"_gray.png");
        //设置灰色状态
        this.isGray = false;
        //设置x和y轴
        this.x = 0;
        this.y = 0;
        //设置大小
        this.width = 100;
        this.height = 100;
        //点击事件
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //获取当前点击卡牌
                Brand b = (Brand) e.getSource();
//                b.getParent().remove(b);
                //如果为true 表示有遮盖
                if (b.isGray || "背景图片".equals(b.getName()) || "消除区域".equals(b.getName())){
                    return;
                }else {
                    //根据父容器 删除子容器
                    //b.getParent().remove(b);
                    cell.setState(0);
                    cell.setBrand(null);
                    Start.m.compareAll();
                    //TestRendarMap.m.compareAll();
                    ElmBox.add(b);
                }
            }
        });
    }
    //绘制图片 g-画笔
    @Override
    public void paint(Graphics g){
        if (this.isGray == true){
            //绘制亮色卡牌
            g.drawImage(grayImage,x,y,null);
        }
        else{
            //绘制灰色卡牌
            g.drawImage(image,x,y,null);
        }
        //repaint();
    }

    //生成set get 方法 alt+insert
    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    public boolean isGray() {
        return isGray;
    }

    public void setGray(boolean gray) {
        isGray = gray;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image getGrayImage() {
        return grayImage;
    }

    public void setGrayImage(Image grayImage) {
        this.grayImage = grayImage;
    }
}